package com.mvcMovie.service.impl;

import com.mvcMovie.bean.MovieRecord;
import com.mvcMovie.bean.UserRecord;
import com.mvcMovie.mapper.MovieRecordMapper;
import com.mvcMovie.mapper.UserRecordMapper;
import com.mvcMovie.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class RecordImpl implements RecordService {

    @Autowired
    private MovieRecordMapper movieRecordMapper;

    @Autowired
    private UserRecordMapper userRecordMapper;
    @Override
    public Integer addUserRecord(UserRecord userRecord) {
        return userRecordMapper.insertUserRecord(userRecord);
    }

    @Override
    public Integer addMovieRecord(MovieRecord movieRecord) {
        return movieRecordMapper.insertMovieRecord(movieRecord);
    }

    @Override
    public Integer addUserRecordAndMovieRecord(UserRecord userRecord, MovieRecord movieRecord) {
        Integer count;
        count = addUserRecord(userRecord);
        count += addMovieRecord(movieRecord);
        return count;
    }

    @Override
    public List<UserRecord> selectAllRecordByUserName(String username) {
        return userRecordMapper.selectAllRecordByUserName(username);
    }

}
